#include "numberbombgame.h"

NumberBombGame::NumberBombGame(QWidget *parent) : QMainWindow(parent), gameOver(false) {
    setFixedSize(300, 200);
    QWidget *centralWidget = new QWidget(this);
    setCentralWidget(centralWidget);

    QVBoxLayout *layout = new QVBoxLayout(centralWidget);

    instructionLabel = new QLabel("Click a button to see if it's a bomb!", this);
    layout->addWidget(instructionLabel);

    // Generate random bomb position
    bombPosition = QRandomGenerator::global()->bounded(1, 10);

    for (int i = 1; i <= 10; ++i) {
        QPushButton *button = new QPushButton(QString::number(i), this);
        layout->addWidget(button);
        connect(button, &QPushButton::clicked, [this, i]() { checkBomb(i); });
        buttons.append(button);
    }
}

void NumberBombGame::checkBomb(int buttonNumber) {
    if (gameOver) return;

    if (buttonNumber == bombPosition) {
        // If the button clicked is the bomb
        instructionLabel->setText("Boom! You clicked on the bomb. Game Over!");
        gameOver = true;
    } else {
        // If the button clicked is not the bomb
        instructionLabel->setText("Phew! You clicked on a safe button. Keep going!");
        buttons[buttonNumber - 1]->setEnabled(false);
    }
}
